﻿SELECT TOP 15
	CustomerName = Customer.Name,
	CustomerCity = Customer.City,
	SalesYear = YEAR(SalesHeader.[Document Date]),
	SalesMonth = MONTH(SalesHeader.[Document Date]),
	SalesAmount = SUM(SalesLine.Amount)
	
FROM
	[CRONUS International Ltd_$Customer] Customer WITH (NOLOCK)

	INNER JOIN [CRONUS International Ltd_$Sales Header] SalesHeader WITH (NOLOCK)
	ON Customer.[No_] = SalesHeader.[Bill-to Customer No_]

	INNER JOIN [CRONUS International Ltd_$Sales Line] SalesLine WITH (NOLOCK)
	ON SalesHeader.[No_] = SalesLine.[Document No_] 
	AND SalesHeader.[Document Type] = SalesLine.[Document Type]

WHERE
	SalesHeader.[Document Date] >= CONVERT(VARCHAR(8), DATEADD(YEAR, -1, GETDATE()), 120) + '01'

GROUP BY
	Customer.Name,
	Customer.City,
	YEAR(SalesHeader.[Document Date]),
	MONTH(SalesHeader.[Document Date])
